package de.tuhh.simsearch.controller.contentmgmt.interfaces;

import java.io.InputStream;
import java.math.BigInteger;
import java.util.List;

import javax.ejb.Local;

import de.tuhh.simsearch.dto.CategoryDTO;
import de.tuhh.simsearch.dto.FileDTO;

/**
 * The remote Interface for the Content Controller. The Content Controller is responsible for file and for category
 * management. The Content controller also handles search requests.
 * 
 * 
 * This should be in the content client project.
 * 
 * @author SimSearch 1
 * 
 */
@Local
public interface ContentControllerInterface {

  /**
   * Searches within the index for a string. It is possible to specify which file attributes (name, category,
   * description...) should be searched.
   * 
   * @param srchstrg
   *          the query
   * @param fields
   *          the fields to be searched
   * @param indexing
   *          true if Lucene should be used, false to search within database
   * @return the resulting list of file dtos
   */
  public List<FileDTO> searchFiles(String srchstrg, String[] fields, boolean indexing);

  /**
   * Searches within categories for a string
   * 
   * @param srchstrg
   *          the string to be searched for
   * @return the resulting list of category dtos
   */
  public List<CategoryDTO> searchCategories(String srchstrg);

  /**
   * Saves a file on the server and stores the metadata in the database. Also calls the indexing functionality.
   * 
   * @param fdto
   *          the FileDTO which contains the metadata
   * @param is
   *          the input stream
   * @return true if upload was successful, else returns false
   */
  public FileDTO uploadFile(FileDTO fdto, InputStream is);

  /**
   * Download a file by submitting a file dto.
   * 
   * @param fdto
   *          the FileDTO of the file to download
   * @return the input stream for the download
   */
  public InputStream downloadFile(FileDTO fdto);

  /**
   * Download a file by file id.
   * 
   * @param id
   *          The id of the file to download
   * @return the input stream for the download
   */
  public InputStream downloadFile(BigInteger id);

  /**
   * Adds a category to the database
   * 
   * @param cdto
   *          the dto of the category to be added
   * @return true if operation was successful
   */
  public boolean addCategory(CategoryDTO cdto);

  /**
   * Gets a category dto.
   * 
   * @param categoryName
   *          the category name
   * @param contentType
   *          the content type of the category
   * @return the category dto
   */
  public CategoryDTO getCategory(String categoryName, String contentType);

  /**
   * Get the FileDTO of a file by submitting its id.
   * 
   * @param id
   *          the id of the file
   * @return the file dto
   */
  public FileDTO getFileInfo(BigInteger id);

  /**
   * Changes the name and content type of a category entity
   * 
   * @param oldcategoryName
   *          the old cateory name
   * @param oldcontentID
   *          the old content type
   * @param newcategoryName
   *          the new category name
   * @param newcontentID
   *          the new category type
   * @return true if operation was successful
   */
  public boolean changeCategory(String oldcategoryName, Integer oldcontentID, String newcategoryName,
      Integer newcontentID);

  /**
   * Removes a category entity from the database
   * 
   * @param categoryName
   *          the category name
   * @param contentID
   *          the content type
   * @return true, if operation was successful
   */
  public boolean removeCategory(String categoryName, Integer contentID);

  /**
   * Removes a file from the server
   * 
   * @param id
   *          the id of the file to remove
   * @return true if successful, else false
   */
  public boolean removeFile(BigInteger id);

}
